/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.shooter;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;

/**
 *
 * @author Unni Vemanchry Mana
 */
public class GameScreen implements Screen, InputProcessor {

    private World world;
    private WorldRenderer renderer;
    private WorldController controller;
    private int width, height;
    
    @Override
    public void render(float f){
     Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
     Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     controller.update(f);
     renderer.render();
    }

    @Override
    public void resize(int w, int h) {
     renderer.setSize(w, h);
     this.width = w;
     this.height = h;
    }

    @Override
    public void show() {
      world    = new World();
      renderer = new WorldRenderer(world, false);
      controller = new WorldController(world);
      Gdx.input.setInputProcessor(this);
    }

    @Override
    public void hide() {
     Gdx.input.setInputProcessor(null);
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void dispose() {
    }

    @Override
    public boolean keyDown(int keycode) {
        System.out.println(keycode);
        if (keycode == Keys.LEFT)
			controller.leftPressed();
		if (keycode == Keys.RIGHT)
			controller.rightPressed();
		if (keycode == Keys.Z)
			controller.jumpPressed();
		if (keycode == Keys.SPACE)
			controller.firePressed();
		return true;
    }

    @Override
    public boolean keyUp(int keycode) {
        if (keycode == Keys.LEFT)
			controller.leftReleased();
		if (keycode == Keys.RIGHT)
			controller.rightReleased();
		if (keycode == Keys.Z)
			controller.jumpReleased();
		if (keycode == Keys.SPACE)
			controller.fireReleased();
        return true;
    }

    @Override
    public boolean keyTyped(char c) {
        return true;
    }

    @Override
    public boolean touchDown(int x, int y, int pointer, int button) {
        controller.touchDown(x, y, pointer, button);
        return true;
    }

    @Override
    public boolean touchUp(int x, int y, int pointer, int button) {
        return true;
    }

    @Override
    public boolean touchDragged(int i, int i1, int i2) {
        controller.touchDragged(i,i1,i2);
        return true;
    }

    @Override
    public boolean touchMoved(int i, int i1) {
        return true;
    }

    @Override
    public boolean scrolled(int i) {
        return true;
    }
    
}
